package com.vooda.controller;

import com.vooda.dto.bo.TicketBo;
import com.vooda.dto.vo.BaseResult;
import com.vooda.dto.vo.HappyBagVo;
import com.vooda.dto.vo.MyTicketVo;
import com.vooda.dto.vo.TicketVo;
import com.vooda.service.TicketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author KennyDavid
 */

@Slf4j
@Api(description = "优惠券")
@RestController
@RequestMapping("/ticket")
@Scope("prototype")
@Validated
public class TicketController extends BaseController {

    @Autowired
    private TicketService ticketService;

    @ApiOperation(value = "获取商户的优惠券列表")
    @GetMapping("/ticketList/{storeId}")
    public BaseResult<List<TicketVo>> ticketList(@ApiParam(value = "商户id", required = true) @PathVariable Long storeId) {
        return ticketService.ticketList(storeId);
    }

    @ApiOperation(value = "获取我的优惠券")
    @GetMapping("/auth/myTicket")
    public BaseResult<List<MyTicketVo>> myTicket(@ApiParam(value = "使用状态：1未使用 2已使用 3已过期", required = true) @RequestParam Integer status) {
        return ticketService.myTicket(getUserId(), status);
    }

    @ApiOperation(value = "我的优惠券详情")
    @GetMapping("/auth/myTicketDetail")
    public BaseResult<MyTicketVo> myTicketDetail(@ApiParam(value = "优惠券id", required = true) @RequestParam Long ticketId) {
        return ticketService.myTicketDetail(getUserId(), ticketId);
    }

    @ApiOperation(value = "领取优惠券")
    @PostMapping("/auth/getTicket/{ticketId}")
    public BaseResult getTicket(@PathVariable Long ticketId) {
        return ticketService.getTicket(getUserId(), ticketId);
    }

    @ApiOperation(value = "领取福袋")
    @PostMapping("/auth/happyBag")
    public BaseResult<List<HappyBagVo>> happyBag() {
        return ticketService.happyBag(getUserId());
    }

    @ApiOperation(value = "扫码使优惠券过期")
    @PutMapping("/auth/scan")
    public BaseResult scan(@ApiParam(value = "从二维码中获取token和ticketId",required = true)@RequestBody TicketBo ticketBo){
        return ticketService.scan(getUserId(),ticketBo);
    }
}
